import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'// Progress 进度条样式
import { getToken } from 'util/token'
import store from './store'

router.beforeEach((to, from, next) => {
  // 非tab模式下 或者tab模式下未加载的页面才显示进度条
  if (store.getters.tabMode) {
    const view = store.getters.visitedViews.find(v => v.path === to.path)
    if (!view.loaded) {
      view.loaded = true
      NProgress.start()
    }
  } else {
    NProgress.start()
  }
  const token = getToken()
  if (token) {
    // 权限判断
    store.dispatch('GetUserInfo')
  }
  next()
})

router.afterEach(() => {
  NProgress.done()
})
